<include file="Public:header" />
<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Operation/js/artTemplate/artTemplate.js"></script>
<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Operation/js/artTemplate/artTemplate-plugin.js"></script>
<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Operation/js/areaSelect/areaSelect.js"></script>

<div class="headbar">
    <div class="position"><span>商品</span><span>></span><span>二维码管理</span><span>></span><span>生成二维码</span></div>
</div>
<div class="content_box">
    <div class="content form_content">
        <form action="{:U('Code/code_save')}" method="post">
            <table class="form_table" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="150px" />
                    <col />
                </colgroup>

                <tr>
                    <th>选择商品：</th>
                    <td>
                        <select class="auto" name="good_id" id="good_id" onchange="spceChange()">
                            <option value="">选择商品</option>
                            <foreach name='goods' item='item'>
                                <option value="{$item['id']}" spec='{$item.spec_array}'>{$item['name']}</option>
                            </foreach>
                        </select>
                    </td>
                </tr>
                <tr  id="spec" style="display:none">
                    <th>请选择规格：</th>
                    <td>
                        <table class="border_table1" id="spec_table">
                            <script type='text/html' id='specTemplate'>
                            <%for(var item in templateData){%>
                            <%item = templateData[item]%>
                            <%var valueItems = parseJSON(item['value']);%>
                            <tr>
                                    <th><%=item["name"]%></th>
                                    <td>
                                            <%if(item['type'] == 1){%>
                                                    <%for(var tempVal in valueItems){%>
                                                    <%tempVal = valueItems[tempVal]%>
                                                            <label class="attr"><input type="radio" name="spec_array[<%=item.id%>]" value='{"id":"<%=item.id%>","type":"<%=item.type%>","value":"<%=tempVal%>","name":"<%=item.name%>"}' /><%=tempVal%></label>
                                                    <%}%>
                                            <%}else if(item['type'] == 2){%>
                                                    <%for(var tempVal in valueItems){%>
                                                    <%tempVal = valueItems[tempVal]%>
                                                            <label class="attr"><input type="radio" name="spec_array[<%=item.id%>]" value='{"id":"<%=item.id%>","type":"<%=item.type%>","value":"<%=tempVal%>","name":"<%=item.name%>"}' /><img src='__ROOT__/<%=tempVal%>' width='30px' height='30px' /></label>
                                                    <%}%>
                                            <%}%>
                                    </td>
                            </tr>
                            <%}%>
                            </script>
                        </table>
                    </td>
                </tr>
                <tr>
                    <th>添加批次：</th><td><input class="normal" name="goods_no" type="text" value=""/></td>
                </tr>
                <tr>
                    <th>发货地：</th>
                    <td>
                        <div class="box">
                            <select name="province" child="city,area" class="auto"></select>
                            <select name="city" child="area" class="auto"></select>
                            <select name="area" class="auto"></select>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>生成个数：</th><td><input class="normal" name="num" type="text" pattern="int" value="" /></td>
                </tr>
                <tr>
                    <td></td><td><button class="submit" type="submit"><span>确 定</span></button></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script language="javascript">  
    $(function(){
        //地区联动插件area_child
        var areaInstance = new areaSelect('province',"{:U('Block/area_child')}");
        areaInstance.init(null);
    });
    
    function spceChange(){
        var spec = $('select[name="good_id"]').find('option:selected').attr('spec');
        var obj = jQuery.parseJSON(spec);
        //alert(obj);die;
        if(obj){
            var specListHtml = template.render('specTemplate',{'templateData':obj});
            $('#spec_table').html(specListHtml);
            $('#spec').show();
        }else{
            $('#spec').hide();
        }
    }
</script>
<include file="Public:footer" />